package com.leyu.mall.site.user.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.leyu.mall.site.utils.UserUtils;
 

/**
 * LoginController负责打开登录页面(GET请求)和登录出错页面(POST请求)， 真正登录的POST请求由Filter完成,
 * 
 * @author change
 * 
 */
@Controller
@RequestMapping(value = "/login")
public class LoginController {
	static final String REDIRECT_URL = "";

	@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
	public String login(HttpServletRequest request) {
		String redirectUrl=request.getParameter(REDIRECT_URL);
        if(!UserUtils.isLogined()){
        	return "user/login.html";
        }
		if(StringUtils.isNotBlank(redirectUrl)){
			return "redirect:"+redirectUrl;
		}
		return "/";
	}

	/*
	 * @RequestMapping(method = RequestMethod.POST) public String
	 * fail(@RequestParam(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM)
	 * String userName, Model model) {
	 * model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM,
	 * userName); model.addAttribute("loginFailure", true); return
	 * "member/login.html"; }
	 */

}
